<script type="text/javascript">
function libConfirm(){
	isValidInfo = true;
	$("#libTitleMsg").html("");
	$("#libFileMsg").html("");
	
	if($("#libTitle").val() == ""){
		$("#libTitleMsg").html("(Vui lòng nhập tiêu đề)");
		isValidInfo = false;
	}

	if ($("#file").val() == ""){
		$("#libFileMsg").html("(Vui lòng chọn file)");
		isValidInfo = false;
	}

	if(isValidInfo){
		var mydata = {};
		var path = $("#file").val();
		mydata['libFileName'] = path.substr(path.lastIndexOf('\\') + 1);
		mydata['subId'] = $("#subId").val();
		$.ajax({
	        type: "POST", 
	        url: "/it_center/Libs/checkFileExist", 
	        data: mydata,
	        success: function(data){  
		        if(data != ""){
			        $("#libFileMsg").html("(" + data + ")");
			        return;
		        }else{
	        		return $("#mainform").submit();
		        }
	       	} 
		});
	}
}

function backToList(subId, subName){
	$("#mainform").prop('action', "/it_center/Libs/list_lib?sub_id=" + subId + "&sub_name=" + subName);
	return $("#mainform").submit();
}

</script>
<section id="content">
<center><H1>Thêm thư viện</H1></center>
<div id="libInfo">
<form id="mainform" method="post" enctype="multipart/form-data" action="/it_center/Libs/confirmLib">
<input type="hidden" name="subId" id="subId" value="<?php echo $subId;?>" />
<input type="hidden" name="subName" value="<?php echo $subName?>"/>
<table id="edit_table">
	<tr>
		<td class="edit_column" width="170">Tiêu đề</td>
		<td>
			<input type="text" name="libTitle" id="libTitle" value="<?php echo $libTitle;?>"/>
			<br/>
			<span id="libTitleMsg" class="errMsg"></span>
		</td>
	</tr>
	<tr>	
		<td class="edit_column">File</td>
		<td>
			<input type="file" name="file" id="file">
			<br/>
			<span id="libFileMsg" class="errMsg"></span>
		</td>
	</tr>
	<tr>	
		<td class="edit_column" style="vertical-align: top;">Mô tả</td>
		<td>
			<textarea name="libDescript" style="width: 99%;" rows="10"><?php echo $libDesc;?></textarea>
		</td>
	</tr>
	<tr>
		<td colspan="2" style="text-align: center;">
			<button type="button" onclick="libConfirm()">Xác nhận</button>
			<button type="button" onclick="backToList(<?php echo $subId;?>, '<?php echo $subName;?>')">Quay Lại</button>
		</td>
	</tr>
</table>
</form>
</div>
</section>